package cn.edu.sdjzu.xg.eagle.bysj.controller;

import cn.edu.sdjzu.xg.eagle.bysj.annotation.IgnoreAuth;
import cn.edu.sdjzu.xg.eagle.bysj.annotation.SysLog;
import cn.edu.sdjzu.xg.eagle.bysj.entity.BaoxiaoshenqingEntity;
import cn.edu.sdjzu.xg.eagle.bysj.entity.view.BaoxiaoshenqingView;
import cn.edu.sdjzu.xg.eagle.bysj.service.Interface.BaoxiaoshenqingService;
import cn.edu.sdjzu.xg.eagle.bysj.utils.MPUtil;
import cn.edu.sdjzu.xg.eagle.bysj.utils.PageUtils;
import cn.edu.sdjzu.xg.eagle.bysj.utils.R;
import com.baomidou.mybatisplus.mapper.EntityWrapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Map;

/**
 * 报销申请
 * 后端接口
 * @author 
 * @email 
 * @date 2025-06-02 13:29:28
 */
@RestController
@RequestMapping("/baoxiaoshenqing")
public class BaoxiaoshenqingController {
    @Autowired
    private BaoxiaoshenqingService baoxiaoshenqingService;


    /**
     * 后台列表
     */
    @RequestMapping("/page")
    public R page(@RequestParam Map<String, Object> params, BaoxiaoshenqingEntity baoxiaoshenqing,
                  HttpServletRequest request){
                    String tableName = request.getSession().getAttribute("tableName").toString();
                                                                                                                                                                                                                                                                                                                                    if(tableName.equals("yuangong")) {
                    baoxiaoshenqing.setShenqingzhanghao((String)request.getSession().getAttribute("username"));
                                    }
                                                                                                                                                    EntityWrapper<BaoxiaoshenqingEntity> ew = new EntityWrapper<BaoxiaoshenqingEntity>();
                                                                                                                                                                                                                                                                                                                            
        
        
        PageUtils page = baoxiaoshenqingService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, baoxiaoshenqing), params), params));
        return R.ok().put("data", page);
    }







    /**
     * 前端列表
     */
	@IgnoreAuth
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params,BaoxiaoshenqingEntity baoxiaoshenqing,
		HttpServletRequest request){
        EntityWrapper<BaoxiaoshenqingEntity> ew = new EntityWrapper<BaoxiaoshenqingEntity>();

		PageUtils page = baoxiaoshenqingService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, baoxiaoshenqing), params), params));
        return R.ok().put("data", page);
    }

	/**
     * 列表
     */
    @RequestMapping("/lists")
    public R list( BaoxiaoshenqingEntity baoxiaoshenqing){
       	EntityWrapper<BaoxiaoshenqingEntity> ew = new EntityWrapper<BaoxiaoshenqingEntity>();
      	ew.allEq(MPUtil.allEQMapPre( baoxiaoshenqing, MPUtil.camelToSnake("baoxiaoshenqing")));
        return R.ok().put("data", baoxiaoshenqingService.selectListView(ew));
    }

	 /**
     * 查询
     */
    @RequestMapping("/query")
    public R query(BaoxiaoshenqingEntity baoxiaoshenqing){
        EntityWrapper< BaoxiaoshenqingEntity> ew = new EntityWrapper< BaoxiaoshenqingEntity>();
 		ew.allEq(MPUtil.allEQMapPre( baoxiaoshenqing, MPUtil.camelToSnake("baoxiaoshenqing")));
		BaoxiaoshenqingView baoxiaoshenqingView =  baoxiaoshenqingService.selectView(ew);
		return R.ok("查询报销申请成功").put("data", baoxiaoshenqingView);
    }
	
    /**
     * 后端详情
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        BaoxiaoshenqingEntity baoxiaoshenqing = baoxiaoshenqingService.selectById(id);
		baoxiaoshenqing = baoxiaoshenqingService.selectView(new EntityWrapper<BaoxiaoshenqingEntity>().eq("id", id));
        return R.ok().put("data", baoxiaoshenqing);
    }

    /**
     * 前端详情
     */
	@IgnoreAuth
    @RequestMapping("/detail/{id}")
    public R detail(@PathVariable("id") Long id){
        BaoxiaoshenqingEntity baoxiaoshenqing = baoxiaoshenqingService.selectById(id);
		baoxiaoshenqing = baoxiaoshenqingService.selectView(new EntityWrapper<BaoxiaoshenqingEntity>().eq("id", id));
        return R.ok().put("data", baoxiaoshenqing);
    }
    



    /**
     * 后端保存
     */
    @RequestMapping("/save")
    @SysLog("新增报销申请")
    public R save(@RequestBody BaoxiaoshenqingEntity baoxiaoshenqing, HttpServletRequest request){
    	//ValidatorUtils.validateEntity(baoxiaoshenqing);
        baoxiaoshenqingService.insert(baoxiaoshenqing);
        return R.ok();
    }
    
    /**
     * 前端保存
     */
    @SysLog("新增报销申请")
    @RequestMapping("/add")
    public R add(@RequestBody BaoxiaoshenqingEntity baoxiaoshenqing, HttpServletRequest request){
    	//ValidatorUtils.validateEntity(baoxiaoshenqing);
        baoxiaoshenqingService.insert(baoxiaoshenqing);
        return R.ok();
    }



    /**
     * 修改
     */
    @RequestMapping("/update")
    @Transactional
    @SysLog("修改报销申请")
    public R update(@RequestBody BaoxiaoshenqingEntity baoxiaoshenqing, HttpServletRequest request){
        //ValidatorUtils.validateEntity(baoxiaoshenqing);
        baoxiaoshenqingService.updateById(baoxiaoshenqing);//全部更新
        return R.ok();
    }



    

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @SysLog("删除报销申请")
    public R delete(@RequestBody Long[] ids){
        baoxiaoshenqingService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }

    	









}
